﻿@model  Model.ETL_Source_ViewConfigInfo
@{
    ViewBag.Title = "配置数据源信息";
    Layout = "~/Views/Shared/_Main.cshtml";
}
@section Head{
    <base target="_self" />
    <style>
        .csvDB
        {
            display: none;
        }
    </style>
    <script type="text/javascript">
        var UrlArray = $.getUrlArray();

        // 预览数据
        function previewData() {
            var dbName = encodeURI(UrlArray["dbName"]);
            var viewID = $("#hddviewID").val();
            var viewName = $(".selFileName").val();
            var systemID = $("#hddsystemID").val();
            var ddlFormat = $("#ddlFileFormat").val();
            var txtTextQualifier = $("#txtTextQualifier").val();
            var ddlLineSeparator = $("#ddlLineSeparator").val();
            var ddlColumnSeparator = $("#ddlColumnSeparator").val();
            var txtSkipRowNum = $("#txtSkipRowNum").val();
            var txtSkipDataNum = $("#txtSkipDataNum").val();

            $.ajax({
                type: "POST",
                url: "/SystemConfiguration/PreviewUpLoadData/",
                data: { dbName: dbName, viewID: viewID, viewName: viewName, systemID: systemID, fileFormat: ddlFormat
                , textQualifier: txtTextQualifier, lineSeparator: ddlLineSeparator, columnSeparator: ddlColumnSeparator
                , skipRowNum: txtSkipRowNum, skipDataNum: txtSkipDataNum
                },
                datatype: "text/plain",
                async: false,
                success: function (result, status) {
                    if (result.Success == true) {
                        $("#viewTb").html(result.Data);
                        //行交替颜色   
                        $("#tableSourceData tr:gt(0):odd").attr("class", "tr_c2");
                        $("#tableSourceData tr:gt(0):even").attr("class", "");

                    }
                    else {
                        if (result.Message != '') {
                            alert(result.Message);
                        } else {
                            alert("预览时出现错误");
                        }
                    }
                },
                error: function (data, status, e) {
                    alert(e);
                }
            });
        }

        function next() {
            var para = "?systemID=" + UrlArray["systemID"] + "&viewID=" + UrlArray["viewID"] + "&dbName=" + encodeURI(UrlArray["dbName"]);
            $.post("/SystemConfiguration/SaveCsvFile" + para,
        { query: jv.GetDivJson($(".table_bg"), 3), dbType: '@Model.IsFile' }, function (result) {
            if (result == "1") {
                showModalMany('Contact', "/SystemConfiguration/SourceColumnEdit" + para + "&fileEdit=true", '810', '480', 'off');
                returnParent("");
            } else {
                alert(result);
            }
        });
        }

        $(function () {
            if ('@Model.IsFile' == '7') {
                $(".csvDB").show();
                $(".txtDB").hide();
            } else {
                $("#ddlFileFormat").val('@Model.FileFormat');
                if ('@Model.LineSeparator' != "\r\n")
                    $("#ddlLineSeparator").val('@Model.LineSeparator');
                $("#ddlColumnSeparator").val('@Model.ColumnSeparator');
            }
            var viewList = "@Model.ViewChnName".split("$");
            for (var i = 0; i < viewList.length; i++) {
                $(".selFileName").append("<option>" + viewList[i] + "</option>");
            }
        });

    </script>
}
<div style="margin: 5px;">
    <input type="hidden" id="hddviewID" name="viewID" value="@Model.Guid" />
    <input type="hidden" id="hddsystemID" name="systemID" value="@Model.SourceSystemID" />
    <table class="listTitle" style="width: 800px;">
        <tr>
            <td width="15">
                <img src="/images/filesave.png" />
            </td>
            <td width="300">
                配置数据源：平面数据源
            </td>
            <td align="right">
                <a id="goto"></a>
                <input id="btnSubmitForm" type="button" class="button" value="下一步" onclick="next();" />
            </td>
        </tr>
    </table>
    <table width="800" class="table_bg" cellpadding="0" cellspacing="0">
        <tr>
            <td style="text-align: right;" width="150">
                格式：
            </td>
            <td width="650">
                &nbsp;带分隔符<select id="ddlFileFormat" name="fileFormat" style="display: none">
                </select>
            </td>
        </tr>
        <tr>
            <td style="text-align: right;">
                文本限定符：
            </td>
            <td>
                &nbsp;<span class="csvDB">"</span><input class="txtDB" type="text" id="txtTextQualifier" maxlength="1" name="textQualifier" value="@Model.TextQualifier" style="width: 113px" />
            </td>
        </tr>
        <tr>
            <td style="text-align: right;">
                行分隔符：
            </td>
            <td>
                &nbsp;<span class="csvDB">{CR}{LF}</span><select class="txtDB" id="ddlLineSeparator"
                    name="txt_lineSeparator" style="width: 120px;">
                    <option value="\r\n">{CR}{LF}</option>
                    <option value="\r">{CR}</option>
                    <option value="\n">{LF}</option>
                    <option value=";">分号 {;}</option>
                    <option value=":">冒号 {:}</option>
                    <option value=",">逗号 {,}</option>
                    <option value="\t">制表符 {t}</option>
                    <option value="|">竖线 {|}</option>
                </select>
            </td>
        </tr>
        <tr>
            <td style="text-align: right;">
                列分隔符：
            </td>
            <td>
                &nbsp;<span class="csvDB">,</span><select class="txtDB" id="ddlColumnSeparator"
                    name="txt_ColumnSeparator" style="width: 120px;">
                    <option value="\r">{CR}</option>
                    <option value="\n">{LF}</option>
                    <option value=";">分号 {;}</option>
                    <option value=":">冒号 {:}</option>
                    <option value="," selected="selected">逗号 {,}</option>
                    <option value="\t">制表符 {t}</option>
                    <option value="|">竖线 {|}</option>
                </select>
            </td>
        </tr>
        <tr>
            <td style="text-align: right;">
                要跳过的标题行数：
            </td>
            <td>
                &nbsp;<input type="text" id="txtSkipRowNum" name="txt_SkipRowNum" onkeyup="this.value=checkNum(this.value)" style="width: 113px"
                    value="@Model.SkipRowNum" />
            </td>
        </tr>
        <tr>
            <td style="text-align: right;">
                要跳过的数据行数：
            </td>
            <td>
                &nbsp;<input type="text" id="txtSkipDataNum" name="txt_SkipDataNum" onkeyup="this.value=checkNum(this.value)" style="width: 113px"
                    value="@Model.SkipDataNum" />
            </td>
        </tr>
        <tr>
            <td colspan="2" style="text-align: right; line-height: 30px">
                选择文件：<select class="selFileName"></select>
                <input type="button" class="button" value="预览" onclick="previewData()" />
            </td>
        </tr>
        <tr>
            <td colspan="2">
                <div runat="server" id="viewTb" style="width: 793px; height: 230px; border: 1px solid #efefef;
                    overflow: scroll">
                </div>
            </td>
        </tr>
    </table>
    <div>
        <div id="loading" class="loading">
            <img src="/Images/tree_loading.gif" />
        </div>
    </div>
</div>
